#include "stdafx.h"
#include "dcom.h"
#include "OtpCom.h"
#include "iauthority.h"

extern "C" __declspec(dllexport)  int CheckGateway(char * pszUsername,char * pszGateway )
{
	HRESULT hr =  CoInitializeEx( NULL, COINIT_MULTITHREADED );
	if(FAILED(hr))
		return (FALSE);

	CIAuthority *pIAuthority= new CIAuthority;
	long lRet= S_FALSE;

	if (TRUE == pIAuthority->Initialize())
	{
		pIAuthority->CheckGateway( pszUsername, pszGateway, &lRet );
		delete pIAuthority;
	}

	CoUninitialize();
	return lRet;
}

extern "C" __declspec(dllexport)  int UserOtpAuth(char * user,char * pwd )
{
	DCom m_dcom;
	if(!m_dcom.DComInit())
		return -99;


	int iret=m_dcom.DComAuthTest(CString(user),
		CString(pwd));
	m_dcom.DComClose();
	
	return iret;
}


extern "C" __declspec(dllexport)  int GetAcctPort()
{
	DCom m_dcom;
	if(!m_dcom.DComInit())
		return -99;

	int iret=m_dcom.DComGetAcctPort();
	m_dcom.DComClose();
	
	return iret;
}


extern "C" __declspec(dllexport)  int GetAuthPort()
{
	DCom m_dcom;
	if(!m_dcom.DComInit())
		return -99;

	int iret=m_dcom.DComGetAuthPort();
	m_dcom.DComClose();
	
	return iret;
}



extern "C" __declspec(dllexport)  int GetClients(char * outBuf)
{
	DCom m_dcom;
	if(!m_dcom.DComInit())
		return -99;


	CString strList;
	int iret=m_dcom.DComReadIp(strList);

	m_dcom.DComClose();

	strList.Replace("@","\t");
	strList.Replace("&","\r\n");
	
	strcpy(outBuf,(const char *)strList);

	return iret;
}
